<include file="Public/header"/>
<include file="Public/menu"/>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.min.js"></script>
<link rel="stylesheet" href="__PUBLIC__/admin/adminlte/plugins/select2/select2.min.css">
<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            活动专题
            <small>管理</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="{:U('manage/index/index')}"><i class="fa fa-dashboard"></i> 活动专题</a></li>
            <li><a href="{:U('special/index')}"><i class="fa fa-dashboard"></i> 专题</a></li>
            <li class="active">编辑</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="box box-info">
                    <div class="box-header with-border">
                        <h3 class="box-title">编辑专题模板</h3>
                        <div class="box-tools">
                            <div class="btn-group pull-right" style="margin-right: 10px">
                                <a href="{:U('special/index')}" class="btn btn-sm btn-default"><i
                                        class="fa fa-list"></i>&nbsp;返回列表</a>
                            </div>
                        </div>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form id="form" action="{:U('special/edit')}" method="post" accept-charset="UTF-8" class="form-horizontal" onsubmit="return checkSubmit()">
                        <input type="hidden" name="id" value="{$info.id}">
                        <input type="hidden" name="template_id" value="{$info.template_id}">
                        <div class="box-body">
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="InputVendorName">专题标题</label>
                                <div class="col-sm-6">
                                    <div class="no-margin">
                                        <input name="title" value="{$info.title}" type="text" class="form-control" placeholder="输入专题标题" disabled>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="InputVendorFullName">副专题标题</label>
                                <div class="col-sm-6">
                                    <div class="no-margin">
                                        <input name="title2" value="{$info.title2}" type="text" class="form-control" placeholder="输入副专题标题" disabled>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="InputVendorFullName">分享导读</label>
                                <div class="col-sm-6">
                                    <div class="no-margin">
                                        <input name="title3" value="{$info.title3}" type="text" class="form-control" placeholder="输入分享导读" disabled>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="InputTel">模板导读</label>
                                <div class="col-sm-6">
                                    <div class="no-margin">
                                        <textarea class="form-control" rows="3" name="title4" placeholder="输入 模板导读"
                                                  id="InputTel" disabled>{$info.title4}</textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">专题活动规描述</label>
                                <div class="col-sm-6">
                                    <div class="no-margin">
                                        <?php  echo html_entity_decode($info['title5'], ENT_QUOTES, 'UTF-8');?>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">专题图片</label>
                                <div class="col-sm-6">
                                    <?php if (!empty($info['img_url'])) { ?>
                                    <div class="col-sm-6" style="margin-left: 274px; margin-top: 5px;">
                                        <img src="/Uploads/{$info['img_url']}" style="height: 100px; ">
                                    </div>
                                    <?php } ?>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">图标</label>
                                <div class="col-sm-6">
                                    <?php if (!empty($info['ico_url'])) { ?>
                                    <div class="col-sm-6" style="margin-left: 274px; margin-top: 5px;">
                                        <img src="/Uploads/{$info['ico_url']}" style="height: 100px; ">
                                    </div>
                                    <?php } ?>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="specialContent">专题内容</label>
                                <div class="col-sm-6">
                                    <textarea id="specialContent">{$info.content}</textarea>
                                    <input type="hidden" name="content" value="{$info.content}">
                                </div>
                            </div>
                            <!--<div class="form-group">
                                <label class="col-sm-2 control-label" for="InputStatus">可见会员来源</label>
                                <div class="col-sm-6">
                                    <select class="form-control  select2-hidden-accessible" style="width: 100%;" id="InputStatus" name="source" tabindex="-1" aria-hidden="true">
                                        <option value="" <if condition="$info['source'] eq ''">selected="selected"</if>">请选择来源</option>
                                        <option value="1" <if condition="$info['source'] eq 1">selected="selected"</if>">平安会员</option>
                                    </select>
                                </div>
                            </div>-->

                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="InputOrderIndex">专题商品包</label>
                                <div class="col-sm-6">
                                    <div class="no-margin">
                                        <volist name="cartList" id="vo">
                                        <label>
                                            <input type="checkbox" class="minimal" name="typeids[]" value="{$vo.type_id}" <?php echo in_array($vo['type_id'], $info['typeids']) ? 'checked': '';?>>
                                            {$vo.type_name}
                                        </label><br>
                                        </volist>
                                    </div>
                                </div>
                            </div>
                            <div for="image" class="form-group 1">
                                <label class="col-sm-2 control-label"></label>
                                <div class="col-sm-6" style="margin-left: 16px; color: #da2424">* 建议选择不超过4个商品包</div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">开始时间</label>
                                <div class="col-sm-6">
                                    <div class="input-group">
                                        <if condition="$info['start_time'] eq ''">
                                            <input id="start_time" name="start_time" class="form-control" type="text" value="" readonly>
                                            <else />
                                            <input id="start_time" name="start_time" class="form-control" type="text" value="{$info.start_time|date='Y-m-d H:i:s',###}" readonly>
                                        </if>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">结束时间</label>
                                <div class="col-sm-6">
                                    <div class="input-group">
                                        <if condition="$info['end_time'] eq ''">
                                            <input id="end_time" name="end_time" class="form-control" type="text" value="" readonly>
                                            <else />
                                            <input id="end_time" name="end_time" class="form-control" type="text" value="{$info.end_time|date='Y-m-d H:i:s',###}" readonly>
                                        </if>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="InputVendorFullName">折扣描述</label>
                                <div class="col-sm-6">
                                    <div class="no-margin">
                                        <input name="price_desc" value="{$info.price_desc}" type="text" class="form-control" id="InputVendorFullName" placeholder="输入折扣描述">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="InputOrderIndex">排序</label>
                                <div class="col-sm-6">
                                    <div class="no-margin">
                                        <input name="idx" value="{$info.idx}" min="1" type="text" class="form-control" id="InputOrderIndex" placeholder="输入排序权重值,数值越小越靠前">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="InputStatusSwitch">是否开启</label>
                                <div class="col-sm-6">
                                    <div class="checkbox">
                                        <label>
                                            <input type="checkbox" id="InputStatusSwitch" value="1" name="state" <if condition="$info['state'] eq 1 or $info['state'] eq ''"> checked="checked" </if> >
                                            选中开启
                                        </label>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- /.box-body -->
                        <div class="box-footer">
                            <input type="hidden" name="_token" value="7lMdsZohP4DDH6f9Pvt6gn9e8TR3yOc34ovag8h3">
                            <div class="col-sm-2">
                            </div>
                            <div class="col-sm-6">
                                <div class="btn-group pull-right">
                                    <button type="submit" class="btn btn-info pull-right">提交</button>
                                </div>
                            </div>

                        </div>
                        <!-- /.box-footer -->
                    </form>
                </div>

            </div>
        </div>

    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer"/>
<link rel="stylesheet" href="/Public/admin/fileinput/fileinput.min.css">
<script src="/Public/admin/fileinput/fileinput.min.js"></script>
<script src="/Public/admin/adminlte/plugins/select2/select2.full.min.js"></script>
<link rel="stylesheet" href="/Public/admin/jedate/jedate.css" />
<script src="/Public/admin/jedate/jedate.js"></script>
<script type="text/javascript">
    // 设置时间
    function setJedate(){
        //不显示秒的解决办法
        var stxt = $("#start_time").val().trim();
        if(stxt.length == 19){
            $("#start_time").val(stxt.substr(0, 16));
        }
        var etxt = $("#end_time").val().trim();
        if(etxt.length == 19){
            $("#end_time").val(etxt.substr(0, 16));
        }
        var start = {
            dateCell: '#start_time',
            format: 'YYYY-MM-DD hh:mm',
            minDate: '1970-01-01 00:00:00',
            festival: false,
            maxDate: '2099-12-31 23:59:59',
            isinitVal:true,
            isTime: true,
            choosefun: function(datas) {
                end.minDate = datas; 
            }
        };
        var end = {
            dateCell: '#end_time',
            format: 'YYYY-MM-DD hh:mm',
            minDate: '1970-01-01 00:00:00',
            festival: false,
            maxDate: '2099-12-31 23:59:59',
            isinitVal:true,
            isTime: true,
            choosefun: function(datas) {
                start.maxDate = datas;
            }
        };
        jeDate(start);
        jeDate(end);
    }
    setJedate();
    $(".select2").select2();

    var ue = UE.getEditor('specialContent', {
        autoHeight: false,
        initialFrameHeight: 500,
    });
    ue.ready(function () {
        //设置编辑器的内容
        /*var content = "<?php echo $info['content'];?>";
         ue.setContent(content);*/
    });

    $('.minimal').change(function (event) {
        var num = 0;
        $('.minimal').each(function () {
            if (this.checked) {
                num ++;
            }
        })
        if(num > 4) {
            $(this).prop('checked', false);
            alert('最多只能启用4个商品包');
        }
    });

    function checkSubmit() {
        var content = ue.getContent();
        $('input[name=content]').val(content);
		return true;
    }
    //todo validate type
    $('.form-horizontal').validate({
        rules: {
			start_time: {
				required: true,
                isActTime: true,
            },
            end_time: {
				required: true,
                isActTime: true,
                dateTimeBigThan: '#start_time'
            },
            price_desc: {
                required: true,
                rangelength :[2,200]
            }
        },
        messages: {
			 start_time: {
				required: "请输入开始时间",
				isActTime: "请输入有效时间"
            },
            end_time: {
				required: "请输入结束时间",
				isActTime: "请输入有效时间",
                dateTimeBigThan: '【注意：】结束时间不能小于开始时间',
            }
        }
    })
</script>


